package net.jjjshop.common.mapper.lbt;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.jjjshop.common.entity.lbt.LbLotteryManager;
import net.jjjshop.common.entity.lbt.LbLotteryOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 公排

 */
@Mapper
public interface LbLotteryManagerMapper extends BaseMapper<LbLotteryManager> {

    @Select("SELECT a.*, SUBSTRING(b.mobile, 8) mobile,b.name from lb_lottery_order a LEFT JOIN(\n" +
            "SELECT user_id,mobile,nickName name FROM jjjshop_user \n" +
            ")b on a.uid=b.user_id\n" +
            "WHERE a.status =1 ORDER BY a.time desc")
   List<LbLotteryManager> getLotteryRecord();

    @Select("SELECT a.*, SUBSTRING(b.mobile, 8) mobile,b.name from lb_lottery_order a LEFT JOIN(\n" +
            "SELECT user_id,mobile,nickName name FROM jjjshop_user \n" +
            ")b on a.uid=b.user_id\n" +
            "WHERE a.status =1 and a.order_no=#{no}")
    LbLotteryOrder getLotteryRecord2(@Param("no")String no);


    /**
     * 查询当前抽奖数据
     * @param limit
     * @return
     */
    @Select("SELECT * from lb_lottery_order WHERE status =0 ORDER BY create_time  LIMIT #{limit} ")
    List<LbLotteryOrder> getLotteryList(@Param("limit")Integer limit);

    /**
     * 查询当前抽奖数据
     * @return
     */
    @Select("SELECT count(*) from lb_lottery_order WHERE status =0")
    Integer getLotteryNum();
}
